package summary;

import java.util.PriorityQueue;

/**
 * @Author: 海琳琦
 * @Date: 2022/6/9 10:54
 * https://leetcode.cn/problems/largest-number-after-digit-swaps-by-parity/
 */
public class Title2231 {

    public int largestInteger(int num) {
        //对奇数进行排序，对偶数进行排序
        PriorityQueue<Integer> queueJ = new PriorityQueue<>((a, b) -> b.compareTo(a));
        PriorityQueue<Integer> queueO = new PriorityQueue<>((a, b) -> b.compareTo(a));
        char[] chars = String.valueOf(num).toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int c = chars[i] - '0';
            if (c % 2 == 0) {
                queueO.offer(c);
            }else{
                queueJ.offer(c);
            }
        }
        int result = 0;
        for (int i = 0; i < chars.length; i++) {
            int c = chars[i] - '0';
            if (c % 2 == 0) {
                result = result * 10 + queueO.poll();
            }else{
                result = result * 10 + queueJ.poll();
            }
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
